package Views;

import UCM.UCCreateUser;
import javax.swing.*;


// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.BEBD7FC5-6604-A2F1-CAA3-0BCA3DE68479]
// </editor-fold> 
/**
 * Creates the create user panel interface
 * @author Josh
 */
public class ViewCreateUser extends JPanel {
    private static int maxChar = 10;
    private MainUI mainView;
    private JPanel userPanel = new JPanel();
    private JPanel passwordPanel = new JPanel();
    private JPanel confirmPasswordPanel = new JPanel();
    private JPanel firstNamePanel = new JPanel();
    private JPanel lastNamePanel = new JPanel();
    private JPanel addressPanel = new JPanel();
    private JLabel userLabel = new JLabel("Name: ");
    private JLabel passwordLabel = new JLabel("Password: ");  
    private JLabel confirmPasswordLabel = new JLabel("Retype Password: ");  
    private JLabel firstNameLabel = new JLabel("First Name: ");
    private JLabel lastNameLabel = new JLabel("Last Name: ");
    private JLabel addressLabel = new JLabel("Address: ");
    private JTextField user = new JTextField(maxChar);
    private JPasswordField password = new JPasswordField(maxChar);
    private JPasswordField confirmPassword = new JPasswordField(maxChar);
    private JTextField firstName = new JTextField(maxChar);
    private JTextField lastName = new JTextField(maxChar);
    private JTextField address = new JTextField(maxChar);
    private JButton createUserButton = new JButton("Create User");
    private final UCCreateUser UCCreateUser = new UCCreateUser(this);
    
    /**
     * public constructor that initualises the view
     * @param view
     */
    public ViewCreateUser(MainUI view) {
        mainView = view;
        this.setLayout(new BoxLayout(this, 1));
        this.add(userPanel);
        userPanel.add(userLabel);
        userPanel.add(user);
        this.add(passwordPanel);
        passwordPanel.add(passwordLabel);
        passwordPanel.add(password);
        password.setEchoChar('*');
        this.add(confirmPasswordPanel);
        confirmPasswordPanel.add(confirmPasswordLabel);
        confirmPasswordPanel.add(confirmPassword);
        confirmPassword.setEchoChar('*');
        this.add(firstNamePanel);
        firstNamePanel.add(firstNameLabel);
        firstNamePanel.add(firstName);
        this.add(lastNamePanel);
        lastNamePanel.add(lastNameLabel);
        lastNamePanel.add(lastName);
        this.add(addressPanel);
        addressPanel.add(addressLabel);
        addressPanel.add(address);
        this.add(createUserButton);
        createUserButton.addActionListener(new AdapterUCCToAL(UCCreateUser));
        this.setVisible(true);
    }

    /**
     * gets the user text
     * @return
     */
    public String getUser() {
        return user.getText();
    }

    /**
     * gets the password
     * @return
     */
    public char[] getPassword() {
        return password.getPassword();
    }

    /**
     * gets the confirm password
     * @return
     */
    public char[] getConfirmPassword() {
        return confirmPassword.getPassword();
    }

    /**
     * gets the first name
     * @return
     */
    public String getFirstName() {
        return firstName.getText();
    }

    /**
     * gets the last name
     * @return
     */
    public String getLastName() {
        return lastName.getText();
    }

    /**
     * gets the address
     * @return
     */
    public String getAddress() {
        return address.getText();
    }

    /**
     * updates the login
     */
    public void updateLogin() {
        mainView.getLoginPanel().updateUISuccess(MainUI.getOnlineUser().getUsername());
    }
}

